﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InfonavaEye.components
{
    public partial class UniDeviceStatusBox : UserControl
    {
        /// <summary>
        /// 相机状态：0 NG, 1.ON, 2.OFF
        /// </summary>
        private int cameraStatus = 0;

        /// <summary>
        /// PLC状态：0 NG, 1.ON, 2.OFF
        /// </summary>
        private int plcStatus = 0;

        /// <summary>
        /// 光源状态：0 NG, 1.ON, 2.OFF
        /// </summary>
        private int lightStatus = 0;

        /// <summary>
        /// 相机状态：0 NG, 1.ON, 2.OFF
        /// </summary>
        [Browsable(true), Category("数据"), Description("相机状态：0 NG, 1.ON, 2.OFF")]
        public int CameraStatus
        {
            get
            {
                return cameraStatus;
            }
            set
            {
                    cameraStatus = value;
                    this.lblCameraStatus.Text = "...";
                    //Task.Run(async () =>
                    //{
                        //await Task.Delay(250);
                        this.lblCameraStatus.Text = getStatus(value);
                    //});
            }
        }

        /// <summary>
        /// PLC状态：0 NG, 1.ON, 2.OFF
        /// </summary>
        [Browsable(true), Category("数据"), Description("PLC状态：0 NG, 1.ON, 2.OFF")]
        public int PLCStatus
        {
            get
            {
                return plcStatus;
            }
            set
            {
                //this.Invoke(new Action(() =>
                //{
                    plcStatus = value;
                    this.lblPLCStatus.Text = "...";
                    Task.Run(async () =>
                    {
                        await Task.Delay(250);
                        this.lblPLCStatus.Text = getStatus(value);
                    });
                //}));
            }
        }

        /// <summary>
        /// 光源状态：0 NG, 1.ON, 2.OFF
        /// </summary>
        [Browsable(true), Category("数据"), Description("光源状态：0 NG, 1.ON, 2.OFF")]
        public int LightStatus
        {
            get
            {
                return lightStatus;
            }
            set
            {
                //this.Invoke(new Action(() =>
                //{
                    lightStatus = value;
                    this.lblLightStatus.Text = "...";
                    Task.Run(async () =>
                    {
                        await Task.Delay(250);
                        this.lblLightStatus.Text = getStatus(value);
                    });
                //}));
            }
        }

        public UniDeviceStatusBox()
        {
            InitializeComponent();
            this.lblCameraStatus.Text = getStatus(cameraStatus);
            this.lblPLCStatus.Text = getStatus(plcStatus);
            this.lblLightStatus.Text = getStatus(lightStatus);
        }

        /// <summary>
        /// 获取状态字符
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        private string getStatus(int status)
        {
            return new string[] { "NG", "ON", "OFF" }[status];
        }
    }
}
